package org.example.innovate.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.example.innovate.common.CommonResponse;
import org.example.innovate.domain.User;
import org.example.innovate.dto.FollowDTO;
import org.example.innovate.service.FollowService;
import org.example.innovate.util.JwtUtil;
import org.example.innovate.vo.DishOneVo;
import org.example.innovate.vo.FollowVo;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Valid
public class FollowController {
    @Resource
    FollowService followService;

    @GetMapping("/follow/{userId}")
    public CommonResponse<List<FollowVo>> getFollowList(
            @RequestParam(defaultValue = "1") Integer page,
            @PathVariable("userId") Integer currentUserId) {
        Page<FollowVo> result = followService.getFollowList(currentUserId, page);
        return CommonResponse.createForSuccess(result.getRecords())
                .setHasMore(result.getCurrent() < result.getPages());
    }

    @GetMapping("/follow/{userId}/fan")
    public CommonResponse<List<FollowVo>> getFanList(
            @RequestParam(defaultValue = "1") Integer page,
            @PathVariable("userId") Integer currentUserId) {

        Page<FollowVo> result = followService.getFanList(currentUserId, page);
        return CommonResponse.createForSuccess(result.getRecords())
                .setHasMore(result.getCurrent() < result.getPages());
    }

    @GetMapping("/follow/list")
    public CommonResponse<List<DishOneVo>> getFollowList(HttpServletRequest request) {
        return followService.getAll(request);
    }

}
